package com.xiangban.data_platform.controller;

import com.xiangban.data_platform.domain.User;
import com.xiangban.data_platform.service.AlternatelyService;
import com.xiangban.data_platform.utils.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Mr. Ma
 * @Data 2020/11/26 11:49
 */
@RestController
@RequestMapping("/api/v1/Alternately")
@Api(tags = "交互管理")
public class AlternatelyController {

    @Autowired
    private AlternatelyService alternatelyService;

    @PostMapping("/savePlatform")
    @ApiOperation("用户添加")
    public JsonData savePlatform(@RequestBody User user){

        int users = alternatelyService.platformsave(user);
        if (users==1){
            return JsonData.buildSuccess("添加成功！");
        }else {
            return JsonData.buildError("添加失败，与同平台信息重复！");
        }
    }

    @PostMapping("/platformdelete")
    @ApiOperation("用户删除")
    public JsonData platformdelete(@RequestBody User user){

        int users = alternatelyService.platformdelete(user);
        if (users==1){
            return JsonData.buildSuccess("已删除！");
        }else {
            return JsonData.buildError("删除失败，无此人信息！");
        }
    }

    @PostMapping("/platformupdate")
    @ApiOperation("用户修改")
    public JsonData platformupdate(@RequestBody User user){

        int users = alternatelyService.platformupdate(user);
        if (users==1){
            return JsonData.buildSuccess("已修改！");
        }else {
            return JsonData.buildError("修改失败，与同平台信息重复！");
        }
    }
}
